# Author: Yubin Lim(purewell@gmail.com)
# Date: 2008-01-18
# License: BSD License
# Copyright: All rights reserved by Yubin Lim.

include(CheckIncludeFile)
include(CheckFunctionExists)
include(CheckTypeSize)

check_include_file("sys/statvfs.h" __PW_HAVE_SYS_STATVFS_H)
check_include_file("statvfs.h" __PW_HAVE_STATVFS_H)

if ( "${__PW_HAVE_SYS_STATVFS_H}" )
	set(CMAKE_EXTRA_INCLUDE_FILES "sys/statvfs.h")
endif ( "${__PW_HAVE_SYS_STATVFS_H}" )

if ( "${__PW_HAVE_STATVFS_H}" )
	set(CMAKE_EXTRA_INCLUDE_FILES "statvfs.h")
endif ( "${__PW_HAVE_STATVFS_H}" )

check_function_exists(statvfs __PW_HAVE_STATVFS)
check_function_exists(fstatvfs __PW_HAVE_FSTATVFS)
check_type_size("struct statvfs" __PW_HAVE_STATVFS_T)

check_include_file("sys/stat.h" __PW_HAVE_SYS_STAT_H)
check_include_file("stat.h" __PW_HAVE_STAT_H)

if ( "${__PW_HAVE_SYS_STAT_H}" )
	set(CMAKE_EXTRA_INCLUDE_FILES "sys/stat.h")
endif ( "${__PW_HAVE_SYS_STAT_H}" )

if ( "${__PW_HAVE_STAT_H}" )
	set(CMAKE_EXTRA_INCLUDE_FILES "stat.h")
endif ( "${__PW_HAVE_STAT_H}" )

check_function_exists(stat __PW_HAVE_STAT)
check_function_exists(lstat __PW_HAVE_LSTAT)
check_function_exists(fstat __PW_HAVE_FSTAT)
check_type_size("struct stat" __PW_HAVE_STAT_T)

set(CMAKE_EXTRA_INCLUDE_FILES "sys/types.h")
check_type_size("dev_t" __PW_HAVE_DEV_T)
check_type_size("ino_t" __PW_HAVE_INO_T)
check_type_size("mode_t" __PW_HAVE_MODE_T)
check_type_size("nlink_t" __PW_HAVE_NLINK_T)
check_type_size("uid_t" __PW_HAVE_UID_T)
check_type_size("gid_t" __PW_HAVE_GID_T)
check_type_size("off_t" __PW_HAVE_OFF_T)
check_type_size("blksize_t" __PW_HAVE_BLKSIZE_T)
check_type_size("__blksize_t" __PW_HAVE___BLKSIZE_T)
check_type_size("blkcnt_t" __PW_HAVE_BLKCNT_T)
check_type_size("intptr_t" __PW_HAVE_INTPTR_T)
check_type_size("void*" __PW_HAVE_POINTER_T)

set(CMAKE_EXTRA_INCLUDE_FILES "sys/socket.h")
check_type_size("struct sockaddr_storage" __PW_HAVE_SOCKADDR_STORAGE_T)

set(CMAKE_EXTRA_INCLUDE_FILES "signal.h")
check_type_size("sigset_t" __PW_HAVE_SIGSET_T)
check_type_size("siginfo_t" __PW_HAVE_SIGINFO_T)

configure_file(purewell.hpp.in "${CMAKE_CURRENT_SOURCE_DIR}/purewell.hpp")
configure_file(types.hpp.in "${CMAKE_CURRENT_SOURCE_DIR}/types.hpp")
add_subdirectory(code)
file(GLOB files "${CMAKE_CURRENT_SOURCE_DIR}/*.hpp")
install(FILES ${files} DESTINATION include/purewell)
